sequenceDiagram
    title 服务购买-支付单同步支付状态

    autonumber

    participant Notify as 支付平台通知
    participant PaymentApplicationService
    participant PaymentOrderRepository

    participant PaymentOrder
    participant PaymentService

    participant DomainEventPublisher



    Notify->>PaymentApplicationService: handleWechatPaymentNotification()

    activate PaymentApplicationService

    PaymentApplicationService->>PaymentOrderRepository: findByOutTradeNo(outTradeNo)

    activate PaymentOrderRepository
    PaymentOrderRepository-->>PaymentApplicationService: PaymentOrder
    deactivate PaymentOrderRepository

    PaymentApplicationService->>PaymentOrder: syncPaymentResult(PaymentService)

    activate PaymentOrder
    PaymentOrder->>PaymentService: queryPaymentStatus(PaymentOrder)

    activate PaymentService
    PaymentService->>PaymentService: 查询支付单实时状态
    PaymentService-->>PaymentOrder: 支付单实时状态
    deactivate PaymentService

    PaymentOrder->>PaymentOrder: 更新内部数据状态

    alt 支付成功
        PaymentOrder->>DomainEventPublisher: 发布领域事件 Paid
    else 支付失败
        PaymentOrder->>DomainEventPublisher: 发布领域事件 PaymentFaild
    end

    deactivate PaymentOrder

    PaymentApplicationService->>PaymentOrderRepository: save(PaymentOrder)

    PaymentApplicationService-->>Notify: 是否接收成功

    deactivate PaymentApplicationService


